package com.weiweiqin.controller.back;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.weiweiqin.model.Feedback;
import com.weiweiqin.service.FeedbackService;
import com.weiweiqin.vo.common.FeedbackTabVO;
import com.weiweiqin.vo.common.Page;
import com.weiweiqin.vo.common.Result;

@Controller
@RequestMapping("admin/feedback")
public class FeedbackController {

	@Autowired
	private FeedbackService feedbackService;

	private static final Logger logger = LoggerFactory
			.getLogger(FeedbackController.class);

	@RequestMapping(value = "/pageList.do", method = { RequestMethod.POST,
			RequestMethod.GET })
	@ResponseBody
	public String pageList(int currPage){
		logger.info("Enter反馈列表");
		Result result = new Result();
		Page page = new Page();
		page.setCurrPage(currPage);
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Map<String,Object> conditions = new HashMap<String, Object>();
		List<Feedback> feedbackList = feedbackService.pageList(page, conditions);
		List<FeedbackTabVO> voList = new ArrayList<FeedbackTabVO>();
		for (Feedback feedback : feedbackList) {
			FeedbackTabVO vo = new FeedbackTabVO();
			vo.setFeedback(feedback);
			String format = sdf.format(feedback.getAddDate());
			vo.setAddDate(format);
			voList.add(vo);
		}
		int totalCount = feedbackService.totalCount(conditions);
		page.setTotalCount(totalCount);
		Map<String,Object> mp = new HashMap<String,Object>();
		mp.put("totalCount",page.getTotalCount());
		mp.put("list", voList);
		result.setObj(mp);
		result.setResult(true);
		return result.toJson();
	}
	
	 
}
